package com.gw.smscheck.controller.business.alarm;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;

import com.gw.smscheck.util.MapUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;

import com.gw.smscheck.util.ResultObj;
import com.gw.smscheck.util.ResultConversion;
import io.swagger.annotations.Api;
import springfox.documentation.annotations.ApiIgnore;
import io.swagger.annotations.ApiOperation;
import com.gw.smscheck.entity.business.alarm.AlarmEnterArea;
import com.gw.smscheck.service.business.alarm.AlarmEnterAreaService;
/**
 * AlarmEnterArea管理
 * 
 * @author wjy
 * @date 2018年11月06日
 */
@Api(description="【模块名称】")
@Controller
@RequestMapping("/alarmEnterAreaController")
public class AlarmEnterAreaController {
	@Autowired
	private AlarmEnterAreaService alarmEnterAreaService;
	/**
	 * 跳转到查询页面
	 * 
	 * @return
	 */
	@RequestMapping("/goPage")
	@ApiIgnore
	public String goPage() {
		return "views/business/alarm/alarmEnterAreaList";
	}
	/**
	 * 跳转到编辑页面
	 * 
	 * @return
	 */
    @RequestMapping(value = "/goEdit")
    @ResponseBody
	@ApiIgnore
	public ModelAndView goEdit(AlarmEnterArea alarmEnterArea) {
		String id = "";
		String row="";
        ModelAndView modelAndView = new ModelAndView("views/business/alarm/alarmEnterAreaEdit");
		if (alarmEnterArea.getId() != null){
			id = alarmEnterArea.getId().toString();
		}
		modelAndView.addObject("id", id);

		return modelAndView;
	}
	/**
	 * 添加
	 * @param response
	 * @param alarmEnterArea
	 * @return
	 */
	@RequestMapping(value = "/add", method = { RequestMethod.POST})
	@ResponseBody
	@ApiOperation(value="添加", notes="添加")
	public String add(HttpServletRequest request,HttpServletResponse response, AlarmEnterArea alarmEnterArea) {
		//User user = (User) request.getSession().getAttribute("user");
		//alarmEnterArea.setCreateUser(String.valueOf(user.getId()));
        if(request.getParameter("geo")!=null&&request.getParameter("geo")!=""){
            alarmEnterArea.setBoundary(MapUtil.getPathString(request.getParameter("geo")));
        }
		return ResultObj.successResultObj(alarmEnterAreaService.add(alarmEnterArea));
	}
	/**
	 * 查询所有
	 * 
	 * @return
	 */
	@RequestMapping(value = "/findAll", method = { RequestMethod.POST})
	@ResponseBody
	@ApiOperation(value="查询所有", notes="查询所有")
	public String findAll() {
		List<AlarmEnterArea> list = alarmEnterAreaService.findAll();
		return JSON.toJSONString(list);
	}
	/**
	 * 分页查询
	 * @param alarmEnterArea
	 * @return
	 */
	@RequestMapping(value = "/pageSelect", method = { RequestMethod.POST })
	@ResponseBody
	@ApiOperation(value="分页查询", notes="分页查询")
	public String pageSelect(AlarmEnterArea alarmEnterArea) {
		PageInfo<AlarmEnterArea> pageInfo = alarmEnterAreaService.pageSelect(alarmEnterArea);
		return ResultConversion.ToEasyUIDataGrid(pageInfo).toJSONString();
	}
	/**
	 * 通过id获取
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "/findById", method = { RequestMethod.POST})
	@ResponseBody
	@ApiOperation(value="通过id获取", notes="通过id获取")
	public String findById(AlarmEnterArea dto){
		return ResultObj.successResultObj(alarmEnterAreaService.findById(dto.getId()));
	}
	/**
	 * 修改
	 * @param alarmEnterArea
	 * @return
	 */
	@RequestMapping(value = "/update", method = { RequestMethod.POST})
	@ResponseBody
	@ApiOperation(value="修改", notes="修改")
	public String update(AlarmEnterArea alarmEnterArea) {
		return ResultObj.successResultObj(alarmEnterAreaService.update(alarmEnterArea));
	}
	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@RequestMapping(value = "/delByIds", method = { RequestMethod.POST})
	@ResponseBody
	@ApiOperation(value="批量删除", notes="批量删除")
	public String delByIds(String[] ids){
		System.out.println(ids.toString());
		return ResultObj.successResultObj(alarmEnterAreaService.delByIds(ids));
	}
}

